﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Entities
{
    public class TableInformation
    {
        public List<Column> ColumnList;

        private DataTable dataTable;

        public DataTable DataTable
        {
            get
            {
                return dataTable;
            }
            set
            {
                dataTable = value;
            }
        }

        public List<string> GetColumnNames()
        {
            List<string> NameList = new List<string>();

            foreach (Column column in ColumnList)
                NameList.Add(column.Name);

            return NameList;
        }

        public DataTable GetRefinedDataTable(List<Column> list)
        {
            int columnCount = list.Count();

            DataTable MyTable = DataTable.Copy();
            StringBuilder sb = new StringBuilder();
            int i;

            for (i = 0; i < columnCount; i++)
                if (list[i].IsImported == false)
                {
                    MyTable.Columns.Remove(ColumnList[i].Name);
                }

            for (i = 0; i < columnCount; i++)
            {
                if (list[i].IsImported == false)
                {
                    list.RemoveAt(i);
                    columnCount--; i--;
                }
            }

            for (i = 0; i < list.Count; i++)
            {
                    sb.Remove(0, sb.Length);
                    sb.Append(list[i].Name);
                    sb.Append(Environment.NewLine);
                    sb.Append("(");
                    sb.Append(list[i].Type1 = list[i].Type1.Replace("System.Windows.Controls.ComboBoxItem: ", ""));
                    sb.Append(")");

                    MyTable.Columns[i].ColumnName = sb.ToString();
            }
           
            return MyTable;
        }

    }
}
